package com.uqbar.arkanoid.components;

import java.awt.Color;
import java.awt.Graphics2D;

import com.uqbar.arkanoid.scenes.ArkanoidScene;
import com.uqbar.arkanoid.scenes.strategies.EstrategiaRaqueta;
import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Rectangle;

public class Raqueta extends GameComponent<ArkanoidScene> {

	private int ancho = 100;
	private int alto = 20;
	private int posicionInicialX = 350;
	private int posicionInicialY = 580;
	private double velocidad;
	private double xMin;
	private double xMax;
	private EstrategiaRaqueta estrategia;
	
	public EstrategiaRaqueta getEstrategia() {
		return estrategia;
	}

	public void setEstrategia(EstrategiaRaqueta estrategia) {
		this.estrategia = estrategia;
	}

	public double getVelocidad() {
		return velocidad;
	}
	
	public double getxMin() {
		return xMin;
	}

	public void setxMin(double xMin) {
		this.xMin = xMin;
	}

	public double getxMax() {
		return xMax;
	}

	public void setxMax(double xMax) {
		this.xMax = xMax;
	}

	public void setVelocidad(double velocidad) {
		this.velocidad = velocidad;
	}
	
	@Override
	public void render(Graphics2D graphics) {
		super.render(graphics);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		this.estrategia.update(this, this.getScene(), deltaState);
		this.coordinarImagen();
		super.update(deltaState);
	}

	public Raqueta(){
		this.setAppearance(new Rectangle(Color.BLACK,this.ancho,this.alto));
		this.setX(this.posicionInicialX);
		this.setY(this.posicionInicialY);
		this.setxMin(0);
		this.setxMax(800);
		this.setVelocidad(500);
		this.setEstrategia(new EstrategiaRaqueta());
	}
	
	public void startGame(){
		if(! (this.getScene().getPelota().isStart())){
			this.getScene().getPelota().start();
		}
	}
	
	private void coordinarImagen(){
		  this.getScene().getSkinRaqueta().setX(this.getX());
		  this.getScene().getSkinRaqueta().setY(this.getY());
	}
	
	public void izquierda(double delta) {
		this.setX(Math.max(this.getX()-getVelocidad()*delta, getxMin()));
	}
	
	public void derecha(double delta) {
		this.setX(Math.min(getxMax() - this.getAppearance().getWidth(), this.getX()+getVelocidad()*delta));
	}
}
